<?php 
ob_clean();
header("content-type:text/html;charset=utf-8");
include_once("/Classes/PHPExcel.php");
$pdo = new PDO("mysql:host=127.0.0.1;dbname=iwebshop","root","root");
$sql = "select * from iwebshop_news";
$res = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$excel = new PHPExcel();
$sheet = $excel->setActiveSheetIndex(0);
$sheet->setCellValue('A1', 'ID')
      ->setCellValue('B1', '用户名')
      ->setCellValue('C1', '密码')->getDefaultStyle()->getFont()->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK));
$i=3;
foreach ($res as $key => $value) {
	$sheet->setCellValue('A1'.$i, $value['id'])
      	  ->setCellValue('B1'.$i, $value['name'])
       	  ->setCellValue('C1'.$i, $value['pwd'])->getDefaultStyle()->getFont()->setSize(10)->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED));
       	$i++;
}

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$objWriter->save('php://output');
exit;

 ?>